﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_CompeteYijiaByPassValve : System.Web.UI.Page
{
    public string BId;
    string ProjectId = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        ProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));

        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (!IsPostBack)
            {
                ProductCode.Text = "";
                ProductName.Text = "";
                Outlookc.Text = "";

                lstCheckStatus.Items.Add("全部");
                lstCheckStatus.Items.Add("审核通过");
                lstCheckStatus.Items.Add("废标");
                LstStatus.Items.Add("全部");
                LstStatus.Items.Add("竞价");
                LstStatus.Items.Add("限价");
                LstStatus.Items.Add("不竞不议");
                LstStatus.Items.Add("备案采购");
            }
            HZ.MBSM.BLL.Compete Compete = new HZ.MBSM.BLL.Compete();
            if (Request.Form["subCompeteYijia"] == "竞价限价分流")
            {
                Compete.CompeteYijiaSeparate(SysFun.ToInt(ProjectId));
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaSeparate(SysFun.ToInt(ProjectId))", "../Agency/CompeteYijiaByPassValve.aspx");
            }

            if (Request.Form["chk"] != null)
            {
                string _strBidId = Request.Form["chk"].ToString() + ",";


                if (Request.Form["subYiJia"] == "限价")
                {
                    Compete.CompeteYijiaByPassValve(_strBidId, 0);
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaByPassValve(_strBidId, 0)" + _strBidId, "../Agency/CompeteYijiaByPassValve.aspx");

                }
                if (Request.Form["subCompete"] == "竞价")
                {
                    Compete.CompeteYijiaByPassValve(_strBidId, 1);
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaByPassValve(_strBidId, 0)" + _strBidId, "../Agency/CompeteYijiaByPassValve.aspx");
                }
                if (Request.Form["subPutOnRecords"] == "备案采购")
                {
                    Compete.CompeteYijiaByPassValve(_strBidId, 3);
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaByPassValve(_strBidId, 0)" + _strBidId, "../Agency/CompeteYijiaByPassValve.aspx");
                }
                if (Request.Form["subNoCompete"] == "不竞不议")
                {
                    Compete.CompeteYijiaByPassValve(_strBidId, 2);
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaByPassValve(_strBidId, 0)" + _strBidId, "../Agency/CompeteYijiaByPassValve.aspx");
                }
                if (Request.Form["subAbolish"] == "废标")
                {
                    Response.Write("<Script>window.open('CompeteAbolish.aspx?Bidid=" + _strBidId.Substring(0, _strBidId.Length - 1) + "')</Script>");
                }
                if (Request.Form["subCancelAbolish"] == "撤销废标")
                {
                    Compete.CompeteYijiaByPassValve(_strBidId, 4);
                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Project_Bid", "Compete.CompeteYijiaByPassValve(_strBidId, 0)" + _strBidId, "../Agency/CompeteYijiaByPassValve.aspx");
                }

            }

            showGridView();
        }
    }


    public void showGridView()
    {
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidgoods_view";                                               //要查询的表明
        dbPage.Key = "bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "MEMO8,factoryusercode,MEMO9,bidid,goodsid,ProductName,Outlookc,UserCode_TB,Factor,Medicinemodel,Unit,ProductCode,salername,factoryname,goodsName,case status when  '0' then '限价' when '1' then '竞价' when '2' then '不竞不议' when '3' then '备案采购' else '未知' end as status, case  when CheckStatus is   null then '未审核' when CheckStatus='0' then '未审核'  when CheckStatus='1' then '审核通过' when CheckStatus='2' then '不通过'   when CheckStatus='3' then '废标' when CheckStatus='4' then '超过限价废标' when CheckStatus='5' then '竞价废标' else '未知' end  as CheckStatus";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "productname,medicinemodel,outlookc,bidid";//排序字段


        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='100%'  align='center' cellpadding='2' cellspacing='1' class='list'>");
        strHtml.Append("<tr>");
        strHtml.Append("<th  nowrap>流水号</th>");
        strHtml.Append("<th  nowrap>注册号</th>");
        strHtml.Append("<th  nowrap>投标人</th>");
        strHtml.Append("<th  nowrap>品目号</th>");
        strHtml.Append("<th  nowrap>通用名</th>");
        strHtml.Append("<th  nowrap>规格</th>");
        strHtml.Append("<th  nowrap>剂型</th>");
        strHtml.Append("<th  nowrap>转换系数</th>");
        strHtml.Append("<th  nowrap>生产厂家</th>");
        strHtml.Append("<th  nowrap>注册号</th>");
        strHtml.Append("<th  nowrap>审核状态</th>");
        strHtml.Append("<th  nowrap>药品状态</th>");
        strHtml.Append("<th  nowrap>选择</th>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();

        while (dr.Read())
        {
            string _strCheckStatus = dr["CheckStatus"].ToString();
            if (_strCheckStatus == "不通过" || _strCheckStatus == "废标" || _strCheckStatus == "超过限价废标" || _strCheckStatus == "竞价废标")
            {
                strHtml.Append("<tr style='background-color:Yellow'>");
            }
            else
            {
                if (i == 0)
                {
                    strHtml.Append("<tr class='table_td'>");
                    i++;
                }
                else
                {
                    strHtml.Append("<tr class='table_td2'>");
                    i--;
                }
            }

            strHtml.Append("<td class='td_center'>" + dr["goodsid"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["UserCode_TB"].ToString() + "</td>");
            strHtml.Append("<td><input type='hidden' name='AccountId' value='" + dr["bidid"].ToString() + "'>" + dr["salername"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["Factor"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["factoryname"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["factoryusercode"].ToString() + "</td>");
            strHtml.Append("<td class='td_center' title='" + dr["MEMO9"].ToString() + "'>" + _strCheckStatus + "</td>");
            strHtml.Append("<td class='td_center'>" + dr["status"].ToString() + "</td>");
            strHtml.Append("<td class='td_center'><input name='chk' type='checkbox' value='" + dr["bidid"].ToString() + "'></td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();

        //BId = Request.Form["bidid"].ToString();
        //GridView1.DataSource = dr;
        //GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键




    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, CheckStatus, _SC, _GoodsId, name, outlookc, productcode, CompanyUserCode, scqyzch;
        productcode = ProductCode.Text.ToString().Trim();
        name = ProductName.Text.ToString().Trim();
        outlookc = Outlookc.Text.ToString().Trim();
        CompanyUserCode = txtCompanyUserCode.Text.ToString().Trim();
        string ProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["projectid"]));
        //projectid = listProject.SelectedValue;
        strtemp = " bidgoods_view.projectid=" + ProjectId + "  and";
        CheckStatus = lstCheckStatus.SelectedValue;
        _SC = SysFun.ToTrim(txtSC.Text);
        _GoodsId = SysFun.ToTrim(txtGoodsId.Text);
        scqyzch = SysFun.ToTrim(txtscqyzch.Text);
        switch (CheckStatus)
        {
            case "全部":
                strtemp += " (CheckStatus='1' or checkstatus>='3') and";
                break;
            case "审核通过":
                strtemp += " CheckStatus='1' and";
                break;
            case "废标":
                strtemp += " CheckStatus>='3' and";
                break;
        }
        //药品状态

        string _strStatus = LstStatus.SelectedValue;
        switch (_strStatus)
        {
            case "全部":
                break;
            case "竞价":
                strtemp += " status=1  and";
                break;
            case "限价":
                strtemp += " status=0  and";
                break;
            case "不竞不议":
                strtemp += " status=2  and";
                break;
            case "备案采购":
                strtemp += " status=3  and";
                break;
        }
        if (scqyzch != "") //按生产企业注册号查询
        {
            strtemp += " factoryusercode like '%" + scqyzch + "%' and";
        }


        if (_GoodsId != "")
        {
            strtemp += " GoodsId like '%" + _GoodsId + "%' and";

        }
        if (_SC != "")
        {
            strtemp += " factoryname like '%" + _SC + "%' and";

        }
        if (productcode != "")
        {
            strtemp += " productcode like '%" + productcode + "%' and";

        }
        if (name != "")
        {
            strtemp += " (ProductName like '%" + name + "%'or SpellingCode like '%" + name + "%') and";
        }
        if (outlookc != "")
        {
            strtemp += " outlookc like '%" + outlookc + "%' and";
        }
        string _strCompanyName_TB = txtCompanyName_TB.Text;
        if (_strCompanyName_TB != "")
        {
            strtemp += " salername like '%" + _strCompanyName_TB + "%' and";
        }
        if (CompanyUserCode != "")
        {
            strtemp += " UserCode_TB like '%" + CompanyUserCode + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }

        return strtemp;

    }



    protected void Button5_Click(object sender, EventArgs e)
    {

    }
}
